package com.cyc.controller;

import com.alibaba.fastjson.JSON;
import com.cyc.entity.Order;
import com.cyc.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.ServletContext;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/order")
public class OrderController {

    @Autowired
    ServletContext servletContext;

    @Autowired
    OrderService orderService;

    @RequestMapping("/select")
    @ResponseBody
    public String select(){
        Map<String, Object> map=new HashMap<>();
        Integer orderid =(Integer) servletContext.getAttribute("orderid");
        Order order = orderService.selectByPrimaryKey(orderid);
        if (order!=null){
            map.put("code",1);
            map.put("msg","购买成功");
        }else {
            map.put("code",0);
            map.put("msg","购买失败");
        }

        return JSON.toJSONString(map);

    }
}
